package com.telecom.cms.service;

import java.util.List;
import com.telecom.cms.dao.CampCampSeqDAO;
import com.telecom.cms.dao.CampSegDAO;
import com.telecom.cms.dao.CampCampDAO;
import com.telecom.cms.dao.SEG_BIZ_ATOM_DEFDAO;
import com.telecom.cms.dao.CampCustInfoDAO;
import com.telecom.cms.dao.CampCustAdvInfoDAO;
import com.telecom.cms.dao.CampTargetFinishTraceDAO;
import com.telecom.cms.dao.CampAdvDAO;
import com.telecom.cms.dto.CampCampSeq;
import com.telecom.cms.dto.CampSeg;
import com.telecom.cms.dto.CampCamp;
import com.telecom.cms.dto.CampAdv;
import com.telecom.cms.dto.SEG_BIZ_ATOM_DEFDTO;
import com.telecom.cms.dto.SEG_BIZ_ATOM_DEFDTO;

public class CampCampSeqMgr {
   
	public void save(CampCampSeq campcamp){
		CampCampSeqDAO dao=new CampCampSeqDAO();
		dao.insert(campcamp);
		dao.insertnum(campcamp);
	}
	
	public void update(CampCampSeq campcamp){
		CampCampSeqDAO dao=new CampCampSeqDAO();
		dao.insert(campcamp);
	}
	
	public void  delete(CampCampSeq campcamp){
		(new CampCampSeqDAO()).delete(campcamp);
	}
	
	public List findall(){
		List result=(new CampCampSeqDAO()).findAll();
		return result;
	}
	public List findall(String campid){
		List result=(new CampCampSeqDAO()).findAll(campid);
		return result;
	}
	
	public CampCampSeq findbyid(String campseqid){
		CampCampSeq result=(new CampCampSeqDAO()).findById(campseqid);
		return result;
	}
	
	
	public void genSeqInfo(String campid,String campseqid,String latncd,String latnId){
		SEG_BIZ_ATOM_DEFDAO segdao=new SEG_BIZ_ATOM_DEFDAO();
		CampCustAdvInfoDAO advdao=new CampCustAdvInfoDAO();
		SEG_BIZ_ATOM_DEFDTO seg=null;
		CampSeg campseg=null;
		CampAdv campadv=null;
		CampCamp campcamp=(new CampCampDAO()).findById(campid);
		(new CampCustInfoDAO()).delete(campid, campseqid);
		
		List campseglist=(new CampSegDAO()).findAll(campid);
		for (int i=0;i<campseglist.size();i++)
		{
			campseg=(CampSeg)campseglist.get(i);
			seg=segdao.findById(campseg.getBizAtomId());
			segdao.genCustInfo(seg, campseg.getCampId(), campseqid, campcamp.getClusterType().trim(), campseg.getShowAreaId(),latncd,latnId);
		}
		
       (new CampCustAdvInfoDAO()).delete(campid, campseqid);
		
		List campadvlist=(new CampAdvDAO()).findAll(campid);
		for (int i=0;i<campadvlist.size();i++)
		{
			System.out.println("advlist"+i);
			campadv=(CampAdv)campadvlist.get(i);
			advdao.genAdvInfo(""+campadv.getCampId(), campseqid, ""+campadv.getAdvInfo(), campadv.getAdvCond(),latncd);
		}
		
		//initalize finish_trace_table
		(new CampTargetFinishTraceDAO()).delete(""+campadv.getCampId(), campseqid);
		(new CampTargetFinishTraceDAO()).insertfromappd(""+campadv.getCampId(), campseqid);
	}
}
